package test.teacher.login.DAO;

import sun.management.Agent;
import test.teacher.Teacher;
import test.teacher.common.utils.DBUtils;

import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @date 2018/5/18  18:37
 */
public class TeacherDao {
    public Teacher queryTeacher(String name,String id) throws PropertyVetoException, SQLException {
        Connection connection = null;
        try {
            connection = DBUtils.getConnection();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
//test version control
        int idd = Integer.parseInt(id);
        String sql = "SELECT id,name,age from jintengbo where name='"+name+"' AND id = '"+id+"'";
        PreparedStatement pstm = connection.prepareStatement(sql);
        ResultSet resultSet = pstm.executeQuery();
        Teacher teacher = null;
       while (resultSet.next()){
            teacher = new Teacher();
            teacher.setId(resultSet.getInt("id"));
            teacher.setName(resultSet.getString("name"));
           teacher.setAge(28);
        }
        return teacher;
    }
}
